#include("/common/_layout.html")
#@layout()
#define layoutHead()
	<title>用户列表</title>
#end
#define layoutBody()
	<body>
		<div class="wrap-container clearfix">
				<div class="column-content-detail">
					<div class="layui-form" action="">
						<div class="layui-form-item">
							<div class="layui-inline tool-btn">
								<button class="layui-btn layui-btn-small layui-btn-normal addBtn" data-url="/admin/edit/user?app_id=#(login_app_id)"><i class="layui-icon">&#xe654;</i></button>
								<button class="layui-btn layui-btn-small layui-btn-danger delBtn"  data-url="/api/user/del" style="display:none"><i class="layui-icon">&#xe640;</i></button>
							</div>
							<div class="layui-inline" style="display:none">
								<select id="so_state" name="so_state" lay-filter="so_state">
									<option value="-100" checked>全部</option>
									<option value="1">启用</option>
									<option value="0">禁用</option>
									<option value="-1">删除</option>
								</select>
							</div>
							<div class="layui-inline">
								<input type="text" id="keywords" name="keywords" placeholder="请输入关键字" autocomplete="off" class="layui-input">
							</div>
							<button class="layui-btn layui-btn-normal" id="btn_search">搜索</button>
						</div>
					</div>
					<div class="layui-form" id="table-list">
						<table class="layui-table" lay-even lay-skin="nob">
							<colgroup>
								<col style="display:none" width="50">
								<col style="display:none" class="hidden-xs" width="50">
								<col>
								<col class="hidden-xs" width="200">
								<col class="hidden-xs" width="200">
								<col class="hidden-xs" width="200">
								<col width="80">
								<col width="80">
								<col width="150">
							</colgroup>
							<thead>
								<tr>
									<th style="display:none"><input type="checkbox" name="allChoose" lay-skin="primary" lay-filter="allChoose"></th>
									<th style="display:none" class="hidden-xs">ID</th>
									<th>登录名</th>
									<th class="hidden-xs">姓名</th>
									<th class="hidden-xs">创建时间</th>
									<th class="hidden-xs">修改时间</th>
									<th>锁定</th>
									<th>状态</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="listTbody">
							</tbody>
						</table>
						<div class="page-wrap">
							<div id="divPager"></div>
						</div>
						
					</div>
				</div>
		</div>
		<!-- #[[ -->
		<script id="tplTbody" type="text/html">
			{{#  layui.each(d.rows, function(index, item){ }}
				<tr>
					<td style="display:none"><input type="checkbox" name="oneChoose" lay-skin="primary" lay-filter="oneChoose" data-id="{{ item.user_id }}"/></td>
					<td class="hidden-xs" style="display:none">{{ item.user_id }}</td>
					<td>{{ item.login_name }}</td>
					<td>{{ formatNullValue(item.user_name) }}</td>
					<td class="hidden-xs">{{ item.reg_time }}</td>
					<td class="hidden-xs">{{ item.update_time }}</td>
					<td class="hidden-xs">{{ item.is_lock }}</td>
					<td>{{ formatState(item.user_state) }}</td>
					<td>
						<div class="layui-inline">
							<button class="layui-btn layui-btn-small layui-btn-normal go-btn" data-id="{{ item.user_id }}" data-url="/admin/edit/user?app_id={{ d.app_id }}"><i class="layui-icon">&#xe642;</i></button>
							<button class="layui-btn layui-btn-small layui-btn-danger del-btn" data-id="{{ item.user_id }}" data-url="/api/user/del"><i class="layui-icon">&#xe640;</i></button>
						</div>
					</td>
				</tr>
			{{#  }); }}
			{{#  if(d.length === 0){ }}
			  无数据
			{{#  } }} 
		</script>
		<!-- ]]# -->
		<script type="text/javascript">
		var page_jump_num = 0;
		layui.use(['layer', 'laypage', 'laytpl', 'form'], function(){
			var laypage = layui.laypage
			,layer = layui.layer
			,laytpl = layui.laytpl;
			var form = layui.form();
			
			$('#btn_search').click(function(){
				page_jump_num = 0;
				getPageData(1);
			});

			// get page data
			function getPageData(pageNo){
				var surl = "/api/user/getPage?pageNo=" + pageNo + "&pageSize=" + global_pagesize + "&state=" + $('#so_state').val() + "&keywords=" + $('#keywords').val() + "&so_app_id=1&state=" + global_allstate;
				document.getElementById('listTbody').innerHTML = "";
				sendPost(surl, null, function(res){
					console.log(res);
					// 首页，渲染分页
					if (page_jump_num == 0){
						renderPage(res.pageData.totalRow);
					}
					if (res.pageData.list.length>0){
						var jdata = {app_id: #(login_app_id), rows: res.pageData.list };
						renderTable(jdata);
					}
				});
			}

			// render pager
			function renderPage(totalPage){
				console.log(totalPage);
				if (totalPage>0){
					page_jump_num = 0;
					laypage.render({
						elem: 'divPager'
						,count: totalPage
						,limit: global_pagesize
						,jump: function(obj){
							
							//首次不执行
							if(page_jump_num>0){
								//console.log(obj);
								getPageData(obj.curr);
							}
							
							page_jump_num++;
						}
					});
				}
			}

			// render table
			function renderTable(listData){
				var getTpl = document.getElementById('tplTbody').innerHTML;
				laytpl(getTpl).render(listData, function(html){
					document.getElementById('listTbody').innerHTML = html;
				});
				form.render("checkbox");
			}

			getPageData(1);
		});

		
		</script>
	</body>

#end